import { userProfilesAPI } from "@/request/api";
export default {
    namespaced: true,
    state: {
        cartTotal: 0,
        userInfo: {
            nickName: "游客",
            coin: 0,
            headImg: require("../../assets/img/service.848ec511.png")
        }
    },
    mutations: {
        // 更新用户信息
        changeUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal
            state.userInfo = payload.userInfo
        },
        // 初始化用户信息
        initUserInfo(state) {
            state.cartTotal = 0,
                state.userInfo = {
                    nickName: "游客",
                    coin: 0,
                    headImg: require("../../assets/img/service.848ec511.png")
                }
        }
    },
    actions: {
        async asyncchangeUserInfo({ commit }, payload) {
            let user = await userProfilesAPI();
            // console.log("用户信息为", user);
            commit("changeUserInfo", user.data)
        }
    }
}